/// @tags:
#include <cctype>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

namespace BlueQuantum {

const int MAXN = 2e5 + 10;
vector<int> g[MAXN << 2];
int n, t[MAXN], ans[MAXN], head[MAXN], cnt, tot = 1, id[MAXN];
struct edge {
  int v, nxt;
} e[MAXN << 1];
void adde(int u, int v) {
  e[++cnt].v = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
int read() {
  int x = 0;
  char ch = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x;
}
namespace LCA {
int dep[MAXN], dfn[MAXN << 1], top, in[MAXN], logg[MAXN << 1], f[MAXN << 1][21];
void dfs(int u, int fa) {
  dep[u] = dep[fa] + 1;
  dfn[++top] = u, f[top][0] = dep[u];
  in[u] = top;
  for (int i = head[u]; i; i = e[i].nxt) {
    if (e[i].v == fa) continue;
    dfs(e[i].v, u);
    dfn[++top] = u;
    f[top][0] = dep[u];
  }
}
void pre() {
  int n = top;
  logg[0] = -1;
  for (int i = 1; i <= n; i++) logg[i] = logg[i >> 1] + 1;
  for (int j = 1; j <= logg[n]; j++)
    for (int i = 1; i + (1 << j) - 1 <= n; i++)
      f[i][j] = min(f[i][j - 1], f[i + (1 << j - 1)][j - 1]);
}
int lca(int x, int y) {
  x = in[x], y = in[y];
  if (x > y) swap(x, y);
  int u = logg[y - x + 1];
  return min(f[x][u], f[y - (1 << u) + 1][u]);
}
int dis(int x, int y) { return dep[x] + dep[y] - 2 * lca(x, y); }
}  // namespace LCA
using namespace LCA;
void modify(int k, int l, int r, int x, int y, int w) {
  if (x <= l && r <= y) {
    g[k].push_back(w);
    return;
  }
  int mid = l + r >> 1;
  if (x <= mid) modify(k << 1, l, mid, x, y, w);
  if (y > mid) modify(k << 1 | 1, mid + 1, r, x, y, w);
}
void query(int k, int l, int r, int p1, int p2, int l1, int l2) {
  for (int i = 0; i < g[k].size(); i++) {
    int u = g[k][i];
    int cur1 = dis(p1, u), cur2 = dis(p2, u);
    if (cur1 < cur2) swap(cur1, cur2), swap(p1, p2);
    int l3 = cur1 + cur2 - l1 >> 1;
    if (l3 > cur2 - l3) {
      p2 = u;
      l1 += 2 * l3 - cur2;
      l2 = max(l2, cur2 - l3);
    } else
      l2 = max(l2, l3);
  }
  if (l == r) {
    ans[l] = l1 + max(0, l2 - 1);
    return;
  }
  int mid = l + r >> 1;
  query(k << 1, l, mid, p1, p2, l1, l2);
  query(k << 1 | 1, mid + 1, r, p1, p2, l1, l2);
}
int main() {
  memset(f, 63, sizeof(f));
  int opt, u;
  n = read();
  for (int i = 1; i <= n; i++) t[i] = n;
  for (int i = 1; i <= n; i++) {
    opt = read();
    u = read();
    if (opt == 1) {
      id[++tot] = i;
      adde(tot, u);
      adde(u, tot);
    } else
      t[u] = i - 1;
  }
  dfs(1, 0);
  pre();
  for (int i = 1; i <= tot; i++) modify(1, 1, n, id[i], t[i], i);
  query(1, 1, n, 1, 1, 0, 0);
  for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("tree.in", "r", stdin);
  freopen("tree.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
